﻿//-----------------------------------------------------------------------
// <copyright file="MidiSynthException.cs" company="Open Source">
//     This file is released under the Microsoft Reciprocal License (Ms-RL)
//     http://www.codeplex.com/wiidrumsynth/license
// </copyright>
//-----------------------------------------------------------------------

namespace MidiSynthLib
{
    using System;
    using System.Collections.Generic;
    using System.Runtime.Serialization;
    using System.Security.Permissions;
    using System.Text;

    /// <summary>
    /// A class which represents an exception which can be raised by the Synth.
    /// </summary>
    [Serializable]
    public class MidiSynthException : Exception
    {
        /// <summary>
        /// An error message explaining the reason for the exception
        /// </summary>
        private string message;

        /// <summary>
        /// Initializes a new instance of the <see cref="MidiSynthException"/> class.
        /// </summary>
        public MidiSynthException()
        {
            this.message = String.Empty;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MidiSynthException"/> class.
        /// </summary>
        /// <param name="message">The message.</param>
        public MidiSynthException(string message)
        {
            this.message = message;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MidiSynthException"/> class.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="innerException">The inner exception</param>
        public MidiSynthException(string message, Exception innerException) :
            base(message, innerException)
        {
            this.message = message;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MidiSynthException"/> class.
        /// </summary>
        /// <param name="info">The Serialization Information</param>
        /// <param name="context">The Streaming Context</param>
        protected MidiSynthException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        /// <summary>
        /// Gets a message that describes the current exception.
        /// </summary>
        /// <value></value>
        /// <returns>The error message that explains the reason for the exception, or an empty string("").</returns>
        public override string Message
        {
            get
            {
                return this.message;
            }
        }

        /// <summary>
        /// Gets the Object Data
        /// </summary>
        /// <param name="info">The Serialization Information</param>
        /// <param name="context">The Streaming Context</param>
        [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
            
            if (info != null)
            {
                info.AddValue("message", this.message);
            }
        }
    }
}
